/*
 * Licensed to the 南京汇海交通科技有限公司
 *
 * Copyright (c) 2025.
 * All rights reserved.
 *
 * 本软件属南京汇海交通科技有限公司所有，在未获得南京汇海交通科技有限公司正式授权情况下，任何企业和个人，不能获取、阅读、安装、传播本软件涉及的任何受知识产权保护的内容。
 */
package com.chframework.boot.web.autoconfigure;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.chframework.boot.core.properties.JacksonProperty;
import com.chframework.json.JacksonHelper;
import com.chframework.monitor.task.MonitorTask;
import com.chframework.common.context.SpringContextHolder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

@Configuration(proxyBeanMethods = false)
@Import(SpringContextHolder.class)
@ComponentScan("com.chframework.boot.web.components")
public class ApplicationAutoConfiguration {

    /**
     * 监控服务器资源占用情况
     */
    @Bean
    public MonitorTask monitorTask() {
        return new MonitorTask();
    }

    /**
     * Jackson序列化与反序列化相关设置
     */
    @Bean
    @ConfigurationProperties(prefix = "application.jackson")
    public JacksonProperty jacksonProperty() {
        return new JacksonProperty();
    }

    /**
     * 集成Jackson通用能力，统一全局Jackson序列化与反序列化配置
     */
    @Bean(name = "objectMapper")
    public ObjectMapper jacksonObjectMapper(JacksonProperty jacksonProperty) {
        return JacksonHelper.getObjectMapper()
                .copy()
                .setSerializationInclusion(jacksonProperty.getJsonInclude());
    }

}
